package com.xgimi.locales.ext

import com.xgimi.locales.utils.Constant
import java.awt.Dimension
import javax.swing.Box
import javax.swing.JCheckBox
import javax.swing.JComponent
import javax.swing.JScrollPane

fun JComponent.labelSize(): JComponent {
    minimumSize = Dimension(100, 30)
    return this
}

fun createCheckBoxListView(list: List<String>,onCreateCheckBox:(cb: JCheckBox, text:String)->Unit): JScrollPane {
    val box = Box.createVerticalBox()
    list.forEach {
//        val text = Constant.langMap[it] ?: ""
        val jCheckBox = JCheckBox("$it")
        onCreateCheckBox(jCheckBox, it)
        box.add(jCheckBox)
    }
    // 滚动窗口
    val jScrollPane = JScrollPane(box)
    val width = 300
    val height = if (list.size > 15) 300 else list.size * 25
    jScrollPane.preferredSize = Dimension(width, height)
    jScrollPane.minimumSize = Dimension(width, height)
    return jScrollPane
}